package com.yezi.lampcourt.base;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.wang.avi.AVLoadingIndicatorView;
import com.yezi.lampcourt.R;

/**
 * Created by HongMing Ye
 * on 2017/10/14 0014.
 */

public class LoadingDialog {
    private Context mContext;
    private Dialog mDialog;
    private AVLoadingIndicatorView mLoadingView;
    private TextView mTvLoading;

    public LoadingDialog(Context context) {
        mContext = context;
        init();
    }

    private void init() {
        View contentView = View.inflate(mContext, R.layout.layout_loading, null);
        mLoadingView = contentView.findViewById(R.id.avi_loadingView);
        mTvLoading = contentView.findViewById(R.id.tv_loading);
        mLoadingView.setIndicatorColor(mContext.getResources().getColor(R.color.colorPrimary));
        mDialog = new Dialog(mContext);
        mDialog.setContentView(contentView);
    }

    public void show() {
        mDialog.show();
        mLoadingView.show();
    }

    public void showWithText(String msg) {
        mTvLoading.setText(msg);
        mDialog.show();
        mLoadingView.show();
    }

    public void showWithoutText() {
        mTvLoading.setVisibility(View.GONE);
        mDialog.show();
        mLoadingView.show();
    }

    public void hide() {
        mDialog.dismiss();
        mLoadingView.hide();
    }
}
